From 0ebae1de2ad042a3db6fb28bc72b4c8ae525460e Mon Sep 17 00:00:00 2001 From: "kaf24@firebug.cl.cam.ac.uk" Date: Fri, 22 Apr 2005 16:10:53 +0000 Subject: [PATCH] bitkeeper revision 1.1367 (4269220d42QVzUVVn9-Tn1tb9fNSWw) Remove memory and cpu parameters from DOM0_CREATEDOMAIN, and remove DOM0_SETINITIALMEM. You can get the same effect via PINCPU, SETMAXMEM, and do_mem_op(increase_reservation). Signed-off-by: Keir Fraser --- tools/libxc/xc.h | 4 -- tools/libxc/xc_domain.c | 46 +++++++++++-------- tools/libxc/xc_private.h | 53 ++++++++++++---------- xen/arch/ia64/dom0_ops.c | 2 - xen/arch/x86/dom0_ops.c | 2 - xen/common/dom0_ops.c | 85 +++++++++++------------------------ xen/common/dom_mem_ops.c | 10 ++--- xen/common/domain.c | 25 ----------- xen/include/asm-ia64/mm.h | 1 - xen/include/public/dom0_ops.h | 16 +------ 10 files changed, 90 insertions(+), 154 deletions(-) diff --git a/tools/libxc/xc.h b/tools/libxc/xc.h index f34dbfc8a9..72c6e10876 100644 --- a/tools/libxc/xc.h +++ b/tools/libxc/xc.h @@ -353,10 +353,6 @@ int xc_physinfo(int xc_handle, int xc_sched_id(int xc_handle, int *sched_id); -int xc_domain_setinitialmem(int xc_handle, - u32 domid, - unsigned int initial_memkb); - int xc_domain_setmaxmem(int xc_handle, u32 domid, unsigned int max_memkb); diff --git a/tools/libxc/xc_domain.c b/tools/libxc/xc_domain.c index 3b85c3b1d6..919145e297 100644 --- a/tools/libxc/xc_domain.c +++ b/tools/libxc/xc_domain.c @@ -14,22 +14,42 @@ int xc_domain_create(int xc_handle, float cpu_weight, u32 *pdomid) { - int err; + int err, errno_saved; dom0_op_t op; op.cmd = DOM0_CREATEDOMAIN; op.u.createdomain.domain = (domid_t)*pdomid; - op.u.createdomain.memory_kb = mem_kb; - op.u.createdomain.cpu = cpu; + if ( (err = do_dom0_op(xc_handle, &op)) != 0 ) + return err; - if ( (err = do_dom0_op(xc_handle, &op)) == 0 ) + *pdomid = (u16)op.u.createdomain.domain; + + if ( (cpu != -1) && + ((err = xc_domain_pincpu(xc_handle, *pdomid, cpu)) != 0) ) + goto fail; + + if ( (err = xc_domain_setcpuweight(xc_handle, *pdomid, cpu_weight)) != 0 ) + goto fail; + + if ( (err = xc_domain_setmaxmem(xc_handle, *pdomid, mem_kb)) != 0 ) + goto fail; + + if ( (err = do_dom_mem_op(xc_handle, MEMOP_increase_reservation, + NULL, mem_kb/4, 0, *pdomid)) != (mem_kb/4) ) { - *pdomid = (u16)op.u.createdomain.domain; - - err = xc_domain_setcpuweight(xc_handle, *pdomid, cpu_weight); + if ( err > 0 ) + errno = ENOMEM; + err = -1; + goto fail; } return err; + + fail: + errno_saved = errno; + (void)xc_domain_destroy(xc_handle, *pdomid); + errno = errno_saved; + return err; } @@ -213,18 +233,6 @@ int xc_domain_setcpuweight(int xc_handle, return ret; } - -int xc_domain_setinitialmem(int xc_handle, - u32 domid, - unsigned int initial_memkb) -{ - dom0_op_t op; - op.cmd = DOM0_SETDOMAININITIALMEM; - op.u.setdomaininitialmem.domain = (domid_t)domid; - op.u.setdomaininitialmem.initial_memkb = initial_memkb; - return do_dom0_op(xc_handle, &op); -} - int xc_domain_setmaxmem(int xc_handle, u32 domid, unsigned int max_memkb) diff --git a/tools/libxc/xc_private.h b/tools/libxc/xc_private.h index 8445e75fbe..f454b5e9b1 100644 --- a/tools/libxc/xc_private.h +++ b/tools/libxc/xc_private.h @@ -72,7 +72,7 @@ static inline int do_xen_hypercall(int xc_handle, static inline int do_dom0_op(int xc_handle, dom0_op_t *op) { - int ret = -1, retries = 0; + int ret = -1, errno_saved; privcmd_hypercall_t hypercall; op->interface_version = DOM0_INTERFACE_VERSION; @@ -86,26 +86,19 @@ static inline int do_dom0_op(int xc_handle, dom0_op_t *op) goto out1; } - again: if ( (ret = do_xen_hypercall(xc_handle, &hypercall)) < 0 ) { - if ( (errno == EAGAIN) && (retries++ < 10) ) - { - /* - * This was added for memory allocation, where we can get EAGAIN - * if memory is unavailable because it is on the scrub list. - */ - sleep(1); - goto again; - } if ( errno == EACCES ) fprintf(stderr, "Dom0 operation failed -- need to" " rebuild the user-space tool set?\n"); - goto out2; } - out2: (void)munlock(op, sizeof(*op)); - out1: return ret; + errno_saved = errno; + (void)munlock(op, sizeof(*op)); + errno = errno_saved; + + out1: + return ret; } static inline int do_dom_mem_op(int xc_handle, @@ -117,7 +110,8 @@ static inline int do_dom_mem_op(int xc_handle, { privcmd_hypercall_t hypercall; long ret = -EINVAL; - + int errno_saved; + hypercall.op = __HYPERVISOR_dom_mem_op; hypercall.arg[0] = (unsigned long)memop; hypercall.arg[1] = (unsigned long)extent_list; @@ -125,7 +119,8 @@ static inline int do_dom_mem_op(int xc_handle, hypercall.arg[3] = (unsigned long)extent_order; hypercall.arg[4] = (unsigned long)domid; - if ( mlock(extent_list, nr_extents*sizeof(unsigned long)) != 0 ) + if ( (extent_list != NULL) && + (mlock(extent_list, nr_extents*sizeof(unsigned long)) != 0) ) { PERROR("Could not lock memory for Xen hypercall"); goto out1; @@ -134,12 +129,18 @@ static inline int do_dom_mem_op(int xc_handle, if ( (ret = do_xen_hypercall(xc_handle, &hypercall)) < 0 ) { fprintf(stderr, "Dom_mem operation failed (rc=%ld errno=%d)-- need to" - " rebuild the user-space tool set?\n",ret,errno); - goto out2; + " rebuild the user-space tool set?\n",ret,errno); + } + + if ( extent_list != NULL ) + { + errno_saved = errno; + (void)munlock(extent_list, nr_extents*sizeof(unsigned long)); + errno = errno_saved; } - out2: (void)munlock(extent_list, nr_extents*sizeof(unsigned long)); - out1: return ret; + out1: + return ret; } static inline int do_mmuext_op( @@ -150,7 +151,8 @@ static inline int do_mmuext_op( { privcmd_hypercall_t hypercall; long ret = -EINVAL; - + int errno_saved; + hypercall.op = __HYPERVISOR_mmuext_op; hypercall.arg[0] = (unsigned long)op; hypercall.arg[1] = (unsigned long)nr_ops; @@ -167,11 +169,14 @@ static inline int do_mmuext_op( { fprintf(stderr, "Dom_mem operation failed (rc=%ld errno=%d)-- need to" " rebuild the user-space tool set?\n",ret,errno); - goto out2; } - out2: (void)munlock(op, nr_ops*sizeof(*op)); - out1: return ret; + errno_saved = errno; + (void)munlock(op, nr_ops*sizeof(*op)); + errno = errno_saved; + + out1: + return ret; } diff --git a/xen/arch/ia64/dom0_ops.c b/xen/arch/ia64/dom0_ops.c index 6fddf360f3..dc8fa16424 100644 --- a/xen/arch/ia64/dom0_ops.c +++ b/xen/arch/ia64/dom0_ops.c @@ -24,8 +24,6 @@ #define TRC_DOM0OP_ENTER_BASE 0x00020000 #define TRC_DOM0OP_LEAVE_BASE 0x00030000 -extern unsigned int alloc_new_dom_mem(struct domain *, unsigned int); - static int msr_cpu_mask; static unsigned long msr_addr; static unsigned long msr_lo; diff --git a/xen/arch/x86/dom0_ops.c b/xen/arch/x86/dom0_ops.c index 65de54fb7e..6f18bfcd8d 100644 --- a/xen/arch/x86/dom0_ops.c +++ b/xen/arch/x86/dom0_ops.c @@ -26,8 +26,6 @@ #define TRC_DOM0OP_ENTER_BASE 0x00020000 #define TRC_DOM0OP_LEAVE_BASE 0x00030000 -extern unsigned int alloc_new_dom_mem(struct domain *, unsigned int); - static int msr_cpu_mask; static unsigned long msr_addr; static unsigned long msr_lo; diff --git a/xen/common/dom0_ops.c b/xen/common/dom0_ops.c index 60a9340582..da454a479a 100644 --- a/xen/common/dom0_ops.c +++ b/xen/common/dom0_ops.c @@ -19,7 +19,6 @@ #include #include -extern unsigned int alloc_new_dom_mem(struct domain *, unsigned int); extern long arch_do_dom0_op(dom0_op_t *op, dom0_op_t *u_dom0_op); extern void arch_getdomaininfo_ctxt( struct exec_domain *, full_execution_context_t *); @@ -153,9 +152,12 @@ long do_dom0_op(dom0_op_t *u_dom0_op) case DOM0_CREATEDOMAIN: { - struct domain *d; - unsigned int pro; - domid_t dom; + struct domain *d; + unsigned int pro; + domid_t dom; + struct exec_domain *ed; + unsigned int i, ht, cnt[NR_CPUS] = { 0 }; + dom = op->u.createdomain.domain; if ( (dom > 0) && (dom < DOMID_FIRST_RESERVED) ) @@ -165,46 +167,32 @@ long do_dom0_op(dom0_op_t *u_dom0_op) break; } else if ( (ret = allocate_domid(&dom)) != 0 ) - break; - - if ( op->u.createdomain.cpu == -1 ) { - /* Do an initial placement. Pick the least-populated CPU. */ - struct domain *d; - struct exec_domain *ed; - unsigned int i, ht, cnt[NR_CPUS] = { 0 }; - - read_lock(&domlist_lock); - for_each_domain ( d ) { - for_each_exec_domain ( d, ed ) - cnt[ed->processor]++; - } - read_unlock(&domlist_lock); - - /* If we're on a HT system, we only use the first HT for dom0, - other domains will all share the second HT of each CPU. - Since dom0 is on CPU 0, we favour high numbered CPUs in - the event of a tie */ - ht = opt_noht ? 1 : ht_per_core; - pro = ht-1; - for ( i = pro; i < smp_num_cpus; i += ht ) - if ( cnt[i] <= cnt[pro] ) - pro = i; + break; } - else - pro = op->u.createdomain.cpu % smp_num_cpus; + + /* Do an initial CPU placement. Pick the least-populated CPU. */ + read_lock(&domlist_lock); + for_each_domain ( d ) + for_each_exec_domain ( d, ed ) + cnt[ed->processor]++; + read_unlock(&domlist_lock); + + /* + * If we're on a HT system, we only use the first HT for dom0, other + * domains will all share the second HT of each CPU. Since dom0 is on + * CPU 0, we favour high numbered CPUs in the event of a tie. + */ + ht = opt_noht ? 1 : ht_per_core; + pro = ht-1; + for ( i = pro; i < smp_num_cpus; i += ht ) + if ( cnt[i] <= cnt[pro] ) + pro = i; ret = -ENOMEM; if ( (d = do_createdomain(dom, pro)) == NULL ) break; - ret = alloc_new_dom_mem(d, op->u.createdomain.memory_kb); - if ( ret != 0 ) - { - domain_kill(d); - break; - } - ret = 0; op->u.createdomain.domain = d->id; @@ -416,33 +404,14 @@ long do_dom0_op(dom0_op_t *u_dom0_op) } break; - case DOM0_SETDOMAININITIALMEM: - { - struct domain *d; - ret = -ESRCH; - d = find_domain_by_id(op->u.setdomaininitialmem.domain); - if ( d != NULL ) - { - /* should only be used *before* domain is built. */ - if ( !test_bit(DF_CONSTRUCTED, &d->d_flags) ) - ret = alloc_new_dom_mem( - d, op->u.setdomaininitialmem.initial_memkb ); - else - ret = -EINVAL; - put_domain(d); - } - } - break; - case DOM0_SETDOMAINMAXMEM: { struct domain *d; ret = -ESRCH; - d = find_domain_by_id( op->u.setdomainmaxmem.domain ); + d = find_domain_by_id(op->u.setdomainmaxmem.domain); if ( d != NULL ) { - d->max_pages = - (op->u.setdomainmaxmem.max_memkb+PAGE_SIZE-1)>> PAGE_SHIFT; + d->max_pages = op->u.setdomainmaxmem.max_memkb >> (PAGE_SHIFT-10); put_domain(d); ret = 0; } diff --git a/xen/common/dom_mem_ops.c b/xen/common/dom_mem_ops.c index 3d55f4b8af..756c26b17c 100644 --- a/xen/common/dom_mem_ops.c +++ b/xen/common/dom_mem_ops.c @@ -41,8 +41,8 @@ alloc_dom_mem(struct domain *d, struct pfn_info *page; unsigned long i; - if ( unlikely(!array_access_ok(extent_list, nr_extents, - sizeof(*extent_list))) ) + if ( (extent_list != NULL) && + !array_access_ok(extent_list, nr_extents, sizeof(*extent_list)) ) return start_extent; if ( (extent_order != 0) && !IS_CAPABLE_PHYSDEV(current->domain) ) @@ -62,7 +62,8 @@ alloc_dom_mem(struct domain *d, } /* Inform the domain of the new page's machine address. */ - if ( unlikely(__put_user(page_to_pfn(page), &extent_list[i]) != 0) ) + if ( (extent_list != NULL) && + (__put_user(page_to_pfn(page), &extent_list[i]) != 0) ) return i; } @@ -79,8 +80,7 @@ free_dom_mem(struct domain *d, struct pfn_info *page; unsigned long i, j, mpfn; - if ( unlikely(!array_access_ok(extent_list, nr_extents, - sizeof(*extent_list))) ) + if ( !array_access_ok(extent_list, nr_extents, sizeof(*extent_list)) ) return start_extent; for ( i = start_extent; i < nr_extents; i++ ) diff --git a/xen/common/domain.c b/xen/common/domain.c index 81a3953739..742ca462a5 100644 --- a/xen/common/domain.c +++ b/xen/common/domain.c @@ -185,31 +185,6 @@ void domain_shutdown(u8 reason) } -unsigned int alloc_new_dom_mem(struct domain *d, unsigned int kbytes) -{ - unsigned int alloc_pfns, nr_pages; - struct pfn_info *page; - - nr_pages = (kbytes + ((PAGE_SIZE-1)>>10)) >> (PAGE_SHIFT - 10); - d->max_pages = nr_pages; /* this can now be controlled independently */ - - /* Grow the allocation if necessary. */ - for ( alloc_pfns = d->tot_pages; alloc_pfns < nr_pages; alloc_pfns++ ) - { - if ( unlikely((page = alloc_domheap_page(d)) == NULL) ) - { - domain_relinquish_resources(d); - return list_empty(&page_scrub_list) ? -ENOMEM : -EAGAIN; - } - - /* Initialise the machine-to-phys mapping for this page. */ - set_machinetophys(page_to_pfn(page), alloc_pfns); - } - - return 0; -} - - /* Release resources belonging to task @p. */ void domain_destruct(struct domain *d) { diff --git a/xen/include/asm-ia64/mm.h b/xen/include/asm-ia64/mm.h index 447bdba8ea..22d3d33917 100644 --- a/xen/include/asm-ia64/mm.h +++ b/xen/include/asm-ia64/mm.h @@ -161,7 +161,6 @@ static inline int get_page(struct pfn_info *page, dummy(); } -// see alloc_new_dom_mem() in common/domain.c #define set_machinetophys(_mfn, _pfn) do { } while(0); #ifdef MEMORY_GUARD diff --git a/xen/include/public/dom0_ops.h b/xen/include/public/dom0_ops.h index ad185ae26d..1086ae85d6 100644 --- a/xen/include/public/dom0_ops.h +++ b/xen/include/public/dom0_ops.h @@ -43,13 +43,9 @@ typedef struct sched_adjdom_cmd dom0_adjustdom_t; #define DOM0_CREATEDOMAIN 8 typedef struct { - /* IN parameters. */ - memory_t memory_kb; - u32 cpu; /* IN/OUT parameters. */ - /* If 0, domain is allocated. If non-zero use it unless in use. */ - domid_t domain; - /* OUT parameters. */ + /* Identifier for new domain (auto-allocate if zero is specified). */ + domid_t domain; } dom0_createdomain_t; #define DOM0_DESTROYDOMAIN 9 @@ -267,13 +263,6 @@ typedef struct { dom0_shadow_control_stats_t stats; } dom0_shadow_control_t; -#define DOM0_SETDOMAININITIALMEM 27 -typedef struct { - /* IN variables. */ - domid_t domain; - memory_t initial_memkb; -} dom0_setdomaininitialmem_t; - #define DOM0_SETDOMAINMAXMEM 28 typedef struct { /* IN variables. */ @@ -390,7 +379,6 @@ typedef struct { dom0_pcidev_access_t pcidev_access; dom0_sched_id_t sched_id; dom0_shadow_control_t shadow_control; - dom0_setdomaininitialmem_t setdomaininitialmem; dom0_setdomainmaxmem_t setdomainmaxmem; dom0_getpageframeinfo2_t getpageframeinfo2; dom0_add_memtype_t add_memtype; -- 2.30.2